package com.wkq.controller;

import com.wkq.domain.Permission;
import com.wkq.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/permission")
public class PermissionController {

    @Autowired
    private IPermissionService iPermissionService;

    @RequestMapping(value = "/findAll")
    @ResponseBody
    public ModelAndView findAll () {
        ModelAndView mv = new ModelAndView();
        List<Permission> permissionList = iPermissionService.findAll();
        mv.addObject("permissionList", permissionList);
        mv.setViewName("permission-list");
        return mv;
    }

    @RequestMapping(value = "/save")
    public String save (Permission permission) {
        int flag = iPermissionService.save(permission);
        if (flag > 0) {
            return "redirect:findAll";
        } else {
            return "redirect:save";
        }
    }
}
